/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utiles;

/**
 *
 * @author Efren
 */
import java.awt.*;
import javax.swing.text.*;
import javax.swing.*;

public class LimitadorDeDocumento extends DefaultStyledDocument {
int caracteresMaximos;

public LimitadorDeDocumento( int caracteresMaximos ) {
this.caracteresMaximos = caracteresMaximos;
}

    @Override
public void insertString(int offs, String str, AttributeSet a)
throws BadLocationException {
if ( (getLength() + str.length()) <= caracteresMaximos)
super.insertString(offs, str, a);
else
Toolkit.getDefaultToolkit().beep();
}
}